<?php
class Slides extends CActiveRecord {
	const DIR = 'slides';
	public $imgPath;
	public $uploadedPic;
	
	public static function model($className = __CLASS__) {
		return parent::model($className);
	}

	public function tableName() {
		return strtolower('Slides');
	}
	
	public function rules() {
		return array(
			array('slideDescr, linkTo', 'required'),
			array('slideOrder', 'numerical')
		);
	}
	
	public function safeAtrributes() {
		return array('slidePic', 'slideDescr', 'linkTo', 'slideOrder');
	}
	
	public static function getSlidePath($fn, $ext = '.jpg') {
		$fn = basename($fn, $ext).$ext;
		$path = Yii::app()->baseUrl.'/uploads/'.self::DIR.'/'.$fn;
		return $path;
	}
	
	public function getAll() {
		$slides = $this->findAll(array('order' => 'slideOrder ASC'));
		foreach($slides as $k => $slide) {
			$slides[$k]->imgPath = self::getSlidePath($slide->slidePic);
		}
		return $slides;
	}
}
